package com.ss.android.article.browser.view.user;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.a.a.e;
import com.a.a.s;
import com.bytedance.common.utility.UIUtils;
import com.ss.android.article.browser.database.BrowserHistory;
import com.ss.android.article.browser.database.bookmark.i;
import com.ss.android.article.browser.view.multiselect.f;
import com.ss.android.common.app.AbsFragment;

import java.util.ArrayList;
import java.util.Iterator;

public final class aaa extends AbsFragment implements com.ss.android.article.browser.view.multiselect.d, f, t, u {
    private RecyclerView a;
    private com.ss.android.article.browser.view.multiselect.a b;
    private com.ss.android.article.browser.database.bookmark.a c;
    private com.ss.android.article.browser.view.user.a.a d;
    private v e;
    private View f;
    private View g;

    public aaa() {

    }

    static View a(aaa arg1) {
        return arg1.f;
    }

    static void a(aaa arg3, boolean arg4) {
        boolean v1 = false;
        View v2 = arg3.g;
        int v0 = arg4 ? 0 : 8;
        UIUtils.setVisibility(v2, v0);
        if (arg3.e != null) {
            v v0_1 = arg3.e;
            if (!arg4) {
                v1 = true;
            }

            v0_1.b(v1);
        }
    }

    public final void a() {
        if (this.e != null) {
            this.e.b();
        }

        this.g();
    }

    public final void a(int arg4) {
        ArrayList<BrowserHistory> v0 = this.d.a;
        if (v0.size() > arg4) {
            String v0_1 = v0.get(arg4).url;
            Intent v1 = new Intent();
            v1.setData(Uri.parse(v0_1));
            FragmentActivity v0_2 = this.getActivity();
            if (v0_2 != null) {
                ((Activity) v0_2).setResult(-1, v1);
                ((Activity) v0_2).finish();
            }
        }
    }

    public final void a(boolean arg2) {
        if (arg2) {
            this.b.c();
        } else {
            this.b.e();
        }
    }

    static View b(aaa arg1) {
        return arg1.g;
    }

    public final void b() {
        if (this.e != null) {
            this.e.c();
        }
    }

    public final void b(int arg2) {
        if (arg2 >= this.d.getItemCount() && this.e != null) {
            this.e.a();
        }

        this.g();
    }

    static com.ss.android.article.browser.view.user.a.a c(aaa arg1) {
        return arg1.d;
    }

    public final void c() {
        this.b.a();
        this.g();
    }

    static com.ss.android.article.browser.view.multiselect.a d(aaa arg1) {
        return arg1.b;
    }

    public final void d() {
        ArrayList<Integer> v0 = this.b.f();
        ArrayList v1 = new ArrayList();
        ArrayList<BrowserHistory> v2 = this.d.a;
        Iterator<Integer> v3 = v0.iterator();
        while (v3.hasNext()) {
            v1.add(v2.get(v3.next().intValue()));
        }

        s v0_1 = s.a(new i(this.c, v1));
        ((e) v0_1).b = android.support.design.a.c();
        ((e) v0_1).c = android.support.design.a.b();
        v0_1.a(new com.ss.android.article.browser.view.user.d(this));
    }

    static v e(aaa arg1) {
        return arg1.e;
    }

    public final void e() {
        this.b.b();
        this.g();
    }

    public final void f() {
        if (this.e != null) {
            v v1 = this.e;
            boolean v0 = this.g.getVisibility() != View.VISIBLE ? true : false;
            v1.b(v0);
        }
    }

    private void g() {
        if (this.e != null) {
            v v1 = this.e;
            boolean v0 = this.b.f().size() > 0 ? true : false;
            v1.a(v0);
        }
    }

    public final void onActivityCreated(@Nullable Bundle arg3) {
        super.onActivityCreated(arg3);
        s v0 = this.c.b();
        ((e) v0).b = android.support.design.a.c();
        ((e) v0).c = android.support.design.a.b();
        v0.a(new c(this));
    }

    public final void onAttach(Context arg2) {
        super.onAttach(arg2);
        if ((arg2 instanceof v)) {
            this.e = ((v) arg2);
        }
    }

    public final void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        this.c = com.ss.android.article.browser.database.bookmark.a.a();
    }

    @Nullable
    public final View onCreateView(LayoutInflater arg6, @Nullable ViewGroup arg7, @Nullable Bundle arg8) {
        this.f = arg6.inflate(com.ss.android.article.browser.R.layout.dv, arg7, false);
        this.a = this.f.findViewById(com.ss.android.article.browser.R.id.recycler_view);
        this.g = this.f.findViewById(com.ss.android.article.browser.R.id.s9);
        this.f.getViewTreeObserver().addOnPreDrawListener(new b(this));
        ((TextView) this.f.findViewById(com.ss.android.article.browser.R.id.s_)).setText(com.ss.android.article.browser.R.string.jg);
        this.a.setLayoutManager(new LinearLayoutManager(this.getContext()));
        w v0 = new w(this.getContext());
        v0.a.setColor(v0.b.getResources().getColor(com.ss.android.article.browser.R.color.fv));
        v0.c = ((int) UIUtils.dp2px(this.getContext(), 20f));
        this.a.addItemDecoration(v0);
        this.d = new com.ss.android.article.browser.view.user.a.a(this.getContext());
        this.b = com.ss.android.article.browser.view.multiselect.c.a(this.getActivity())
                .a(this.d)
                .a(this.d.a)
                .a(new com.ss.android.article.browser.view.multiselect.viewholder.a.a((byte) 0))
                .a(((f) this))
                .a(((com.ss.android.article.browser.view.multiselect.d) this))
                .a();
        this.a.setAdapter(this.b);
        return this.f;
    }

    public final void onDetach() {
        super.onDetach();
        this.e = null;
    }

    public final void onResume() {
        super.onResume();
        if (this.e != null) {
            v v1 = this.e;
            boolean v0 = !this.d.a.isEmpty() ? true : false;
            v1.b(v0);
        }
    }
}

